package controller

import (
	"github.com/gin-gonic/gin"
	"shop-common/library/serializer"
	"shop-common/utils/contextArgs"
	"shop-common/utils/pagehelper"
	"shop-service/business"
)

type UserController struct {
}

// @Tags 会员管理
// @description: 会员分页
// @Summary 会员分页
// @Security ApiKeyAuth
// @function: Page
// @Accept  json
// @Produce  json
// @Param current query string false "当前页，默认1"
// @Param size query string false "每页大小，默认10"
// @Param keyword query string false "keyword"
// @Param status query int false "状态  1:无效  2:正常"
// @Success 200 {object} string "{"code":0," result":{}, "message":"操作成功", "time":1618493448}"
// @Router /admin/user/page [get]
func (u *UserController) Page(ctx *gin.Context) {
	form := pagehelper.SearchPageRequest{}
	if err := serializer.Verify(ctx, &form); err != nil {
		serializer.Fail(ctx, err.Error())
		return
	}

	page, err := business.ServiceImpl().UserService.Page(&form)
	if err != nil {
		serializer.Fail(ctx, serializer.PublicQueryErr)
		return
	}

	serializer.SuccessData(ctx, "", &page)
}

// @Tags 会员管理
// @Summary 会员信息
// @description: 会员信息
// @Security ApiKeyAuth
// @function: Info
// @Accept  json
// @Produce  json
// @Param userId path string true "userId"
// @Success 200 {object} string "{"code":0," result":{}, "message":"操作成功", "time":1618493448}"
// @Router /admin/user/info/{userId} [get]
func (u *UserController) Info(ctx *gin.Context) {
	userId, err := contextArgs.GetUriPath(ctx, "userId")
	if err != nil {
		serializer.Fail(ctx, err.Error())
		return
	}

	info, err := business.ServiceImpl().UserService.FindById(userId)
	if err != nil {
		serializer.Fail(ctx, err.Error())
		return
	}

	serializer.SuccessData(ctx, "", &info)
}
